import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout' // 导入组件 表示为src/layout

export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: 'Dashboard',
      component: () => import('@/views/dashboard/index'),
      meta: { title: 'Dashboard', icon: 'dashboard' }
    }]
  },

  {
    path: '/example',
    component: Layout,
    redirect: '/example/echarts',
    name: 'Echarts',
    meta: { title: 'Echarts', icon: 'el-icon-s-help' },
    children: [
      {
        path: 'echarts1',
        name: 'Echarts1',
        component: () => import('@/views/echarts/Echarts1'),
        meta: { title: '折线图', icon: 'table' }
      },
      {
        path: 'echarts2',
        name: 'Echarts2',
        component: () => import('@/views/echarts/Echarts2'),
        meta: { title: '圆柱图', icon: 'tree' }
      },
      {
        path: 'echarts3',
        name: 'Echarts3',
        component: () => import('@/views/echarts/Echarts3'),
        meta: { title: '面积图', icon: 'table' }
      },
      {
        path: 'echarts4',
        name: 'Echarts4',
        component: () => import('@/views/echarts/Echarts4'),
        meta: { title: '饼图', icon: 'tree' }
      }
    ]
  },
  {
    path: '/X',
    component: Layout,
    redirect: '/X/A',
    name: 'X',
    meta: { title: '功能模块', icon: 'el-icon-s-help' },
    children: [
      {
        path: 'A',
        name: 'A',
        component: () => import('@/views/X/A'),
        meta: { title: 'A组件', icon: 'table' }
      },
      {
        path: 'B',
        name: 'B',
        component: () => import('@/views/X/B'),
        meta: { title: 'B组件', icon: 'tree' }
      },
      {
        path: 'C',
        name: 'C',
        component: () => import('@/views/X/C'),
        meta: { title: 'C组件', icon: 'tree' }
      },
      {
        path: 'D',
        name: 'D',
        component: () => import('@/views/X/D'),
        meta: { title: 'D组件', icon: 'tree' }
      },
      {
        path: 'E',
        name: 'E',
        component: () => import('@/views/X/E'),
        meta: { title: 'E组件', icon: 'tree' }
      },
      {
        path: 'F',
        name: 'F',
        component: () => import('@/views/X/F'),
        meta: { title: 'F组件', icon: 'tree' }
      },
      {
        path: 'G',
        name: 'G',
        component: () => import('@/views/X/G'),
        meta: { title: 'G组件', icon: 'tree' }
      },
      {
        path: 'H',
        name: 'H',
        component: () => import('@/views/X/H'),
        meta: { title: 'H组件', icon: 'tree' }
      },
      {
        path: 'M',
        name: 'M',
        component: () => import('@/views/X/M'),
        meta: { title: 'M组件', icon: 'tree' }
      }]
  },
  {
    path: '/hongyi',
    component: Layout,
    redirect: '/hongyi/xtm',
    name: 'hongyi',
    meta: { title: '功能模块01', icon: 'el-icon-s-help' },
    children: [
      {
        path: 'hongyi',
        name: 'hongyi',
        component: () => import('@/views/hongyi/hongyi'),
        meta: { title: 'hongyi', icon: 'table' }
      },
      {
        path: 'xtm',
        name: 'xtm',
        component: () => import('@/views/hongyi/xtm'), // @表示src
        meta: { title: 'xtm', icon: 'tree' }
      }, {
        path: 'anli',
        name: 'anli',
        component: () => import('@/views/hongyi/anli'), // @表示src
        meta: { title: '案例模块', icon: 'tree' }
      }]
  },
  {
    path: '/Basi_Information',
    component: Layout,
    redirect: '/kemu',
    name: 'Basi_Information',
    meta: { title: '基础信息', icon: 'el-icon-s-help' },
    children: [
      {
        path: 'kemu',
        name: 'kemu',
        component: () => import('@/views/Basi_Information/kemu'),
        meta: { title: '科目设置', icon: 'table' }
      },
      {
        path: 'kaoshiyaoqiu',
        name: 'kaoshiyaoqiu',
        component: () => import('@/views/Basi_Information/kaoshiyaoqiu'), // @表示src
        meta: { title: '考试要求目标设置', icon: 'tree' }
      }]
  },
  {
    path: '/axios',
    component: Layout,
    redirect: '/axios/A',
    name: 'axios',
    meta: { title: 'axios框架', icon: 'el-icon-s-help' },
    children: [
      {
        path: 'A',
        name: 'S',
        component: () => import('@/views/axios/A'),
        meta: { title: 'A', icon: 'table' }
      },
      {
        path: 'B',
        name: 'B',
        component: () => import('@/views/axios/B'), // @表示src
        meta: { title: 'B', icon: 'tree' }
      }, {
        path: 'C',
        name: 'C',
        component: () => import('@/views/axios/C'), // @表示src
        meta: { title: '树形结构', icon: 'tree' }
      }, {
        path: 'dep',
        name: 'dep',
        component: () => import('@/views/axios/dep'), // @表示src
        meta: { title: '一对多模块树形结构', icon: 'tree' }
      }, {
        path: 'dep01',
        name: 'dep01',
        component: () => import('@/views/axios/dep01'), // @表示src
        meta: { title: '员工信息01', icon: 'tree' }
      },
      {
        path: 'Student',
        name: 'student',
        component: () => import('@/views/axios/Student'), // @表示src
        meta: { title: '学生个人信息模块', icon: 'tree' }
      },
      {
        path: 'Student12',
        name: 'student12',
        component: () => import('@/views/axios/Student12'), // @表示src
        meta: { title: '用户管理', icon: 'tree' }
      },
      {
        path: 'SystemPost',
        name: 'SystemPost',
        component: () => import('@/views/axios/SystemPost.vue'), // @表示src
        meta: { title: '岗位管理', icon: 'tree' }
      },
      {
        path: 'SystemDept',
        name: 'SystemDept',
        component: () => import('@/views/axios/SystemDept.vue'), // @表示src
        meta: { title: '部门管理', icon: 'tree' }
      },
      {
        path: 'SystemRole',
        name: 'SystemRole',
        component: () => import('@/views/axios/SystemRole.vue'), // @表示src
        meta: { title: '角色管理', icon: 'tree' }
      },
      {
        path: 'SystemMenu',
        name: 'SystemMenu',
        component: () => import('@/views/axios/SystemMenu.vue'), // @表示src
        meta: { title: '菜单管理', icon: 'tree' }
      }]
  },

  {
    path: '/form',
    component: Layout,
    children: [
      {
        path: 'index',
        name: 'Form',
        component: () => import('@/views/form/index'),
        meta: { title: 'Form', icon: 'form' }
      }
    ]
  },

  {
    path: '/nested',
    component: Layout,
    redirect: '/nested/menu1',
    name: 'Nested',
    meta: {
      title: 'Nested',
      icon: 'nested'
    },
    children: [
      {
        path: 'menu1',
        component: () => import('@/views/nested/menu1/index'), // Parent router-view
        name: 'Menu1',
        meta: { title: 'Menu1' },
        children: [
          {
            path: 'menu1-1',
            component: () => import('@/views/nested/menu1/menu1-1'),
            name: 'Menu1-1',
            meta: { title: 'Menu1-1' }
          },
          {
            path: 'menu1-2',
            component: () => import('@/views/nested/menu1/menu1-2'),
            name: 'Menu1-2',
            meta: { title: 'Menu1-2' },
            children: [
              {
                path: 'menu1-2-1',
                component: () => import('@/views/nested/menu1/menu1-2/menu1-2-1'),
                name: 'Menu1-2-1',
                meta: { title: 'Menu1-2-1' }
              },
              {
                path: 'menu1-2-2',
                component: () => import('@/views/nested/menu1/menu1-2/menu1-2-2'),
                name: 'Menu1-2-2',
                meta: { title: 'Menu1-2-2' }
              }
            ]
          },
          {
            path: 'menu1-3',
            component: () => import('@/views/nested/menu1/menu1-3'),
            name: 'Menu1-3',
            meta: { title: 'Menu1-3' }
          }
        ]
      },
      {
        path: 'menu2',
        component: () => import('@/views/nested/menu2/index'),
        name: 'Menu2',
        meta: { title: 'menu2' }
      }
    ]
  },

  {
    path: 'external-link',
    component: Layout,
    children: [
      {
        path: 'https://panjiachen.github.io/vue-element-admin-site/#/',
        meta: { title: 'External Link', icon: 'link' }
      }
    ]
  },

  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
